key_pressed
This function checks if a particular key on the keyboard has just been pushed down.
bool key_pressed(int key)
Parameters:
key
One of the BGT key name constants, see appendix A for a full list.
Return value:
true if the key has just been pushed down, false if it has not or if an error occurs.
Remarks:
The difference between key_down and key_pressed is that key_pressed will only return true when the user first pushes down the key, while key_down will continue returning true until the key is released again.
Example:
// Wait for the user to hold down alt and press f4 before closing the program.
void main()
{
show_game_window("Test Game");
while(true)
{
if(key_down(KEY_LMENU) && key_pressed(KEY_F4))
{
exit();
}
// Other code goes here.
wait(5);
}
}